import 'package:flutter/material.dart';

import '../../../dao/group_dao.dart';

class GroupItemWidget extends StatefulWidget {
  GroupItemWidget( this.groupId,this.order, this.groupName, this.groupAvatar,
      this.selfRecommendation, this.hotIndex,
      {super.key});
  num groupId;
  int order;
  String groupAvatar;
  String groupName;
  String selfRecommendation;
  int hotIndex;

  @override
  State<GroupItemWidget> createState() => _GroupItemWidgetState();
}

class _GroupItemWidgetState extends State<GroupItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.symmetric(vertical: 5),
      margin: EdgeInsets.symmetric(vertical: 3),
      height: 80,
      child: Flex(
        direction: Axis.horizontal,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(flex: 1, child: Text(widget.order.toString())),
          Expanded(
            flex: 4,
            child: CircleAvatar(
              radius: 30,
              backgroundImage: NetworkImage(
                widget.groupAvatar!,
              ),
            ),
          ),
          Expanded(
              flex: 8,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(widget.groupName,style: TextStyle(fontSize: 18),),
                  Text(widget.selfRecommendation),
                  Text(widget.hotIndex.toString()),
                ],
              )),
          Expanded(
              flex: 2,
              child: FilledButton(
                onPressed: () {
                  GroupDao.joinGroup(widget.groupId, 0);
                },
                child: Text("加入"),
                style: ButtonStyle(
                    minimumSize: MaterialStateProperty.all(Size(60, 30)),
                    padding: MaterialStateProperty.all(EdgeInsets.zero)),
              )),
        ],
      ),
    );
  }
}
